package keyctrl
{
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;

	public class KeyManager
	{
		
		private static var _keyStates:Object;
		
		
		
		
		public function KeyManager()
		{
		}
		
		public static function init( _stage:Stage ):void
		{
			_stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
			
			_stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
			
			_keyStates = {};
			
		}
		
		public static function keyUpHandler( e:KeyboardEvent ):void
		{
			_keyStates[e.keyCode] = false;
			
			e.stopImmediatePropagation();
			
			e.stopPropagation();
			
		}
		
		public static function keyDownHandler( e:KeyboardEvent ):void
		{
			_keyStates[e.keyCode] = true;
			
			e.stopImmediatePropagation();
			
			e.stopPropagation();
			
		}
		
		public static function isDown( keyCode:uint ):Boolean
		{
			return _keyStates[keyCode];
		}
		
		public static function get SHIFT_DOWN():Boolean
		{
			return isDown( Keyboard.SHIFT );
		}
		
		public static function get CTRL_DOWN():Boolean
		{
			return isDown( Keyboard.CONTROL );
		}
		
		public static function get ALT_DOWN():Boolean
		{
			return isDown( Keyboard.ALTERNATE );
		}
		
	}
}